

#include <cegfx/cetimer.h>
#include <cegfx/cevirtualclock.h>
#include <stdio.h>

ceTimer::ceTimer (long time)
	: time(0)
	, elapsed (0)
	, frame (0)
	, fps (0)
{
	time = ceVClock::GetMilliseconds ();
	elapsed = time + time;
	lastSec = time;
};


long ceTimer::GetTime () const
{
	return ceVClock::GetMilliseconds () - time;
}

bool ceTimer::IsElapsed () const
{
	return ceVClock::GetMilliseconds () >= elapsed;
}

void ceTimer::Tick () 
{
	frame++;
	if ((ceVClock::GetMilliseconds () - lastSec) > 1000)
	{
		lastSec += 1000;
		fps = frame;
		frame = 0;
	}
}

unsigned ceTimer::GetFPS () const
{
	return fps;
}

